import { queryReporting, showReporting,updata ,videoSign,videoDetails, fetchThirdData, fetchThirdDataDetails, fetchThirdDataCreate} from '../services/api';
import { message } from 'antd';

export default {
  namespace: 'queries',

  state: {
    reportingList: [],
    inquiryList: {},
    videoSignList: [],
    videoDetailsList: null,
    page: [],
    thirdData: null,
    thirdDataPage: null,
    thirdDataLoading: false,
    loading: false,
    sumbitLoading: false,
    thirdDataDetails: null,
    thirdDataResult: null,
  },

  effects: {

    *fetch({ payload }, { call, put }) {
      // console.log("payload1征信列表",payload)
      yield put({
        type: 'query',
        payload: {
          loading: true,
        },
      });
      const response = yield call(queryReporting, payload);
      // console.log("response1征信列表接口",response)
      yield put({
        type: 'query',
        payload: {
          reportingList: response.data.list,
          page: response.data.page,
          loading: false,
        },
      });
    },

    *videoList({ payload }, { call, put }) {
      // console.log("payload",payload)
      yield put({
        type: 'query',
        payload: {
          loading: true,
        },
      });
      const response = yield call(videoSign, payload);
      // console.log("response",response)
      yield put({
        type: 'query',
        payload: {
          videoSignList: response.data.list,
          page: response.data.page,
          loading: false,
        },
      });
    },

    *videoDetails({ payload }, { call, put }) {
      yield put({
        type: 'query',
        payload: {
          loading: true,
        },
      });
      const response = yield call(videoDetails, payload);
      yield put({
        type: 'query',
        payload: {
          loading: false,
        },
      });
      yield put({
        type: 'query',
        payload: {
          videoDetailsList: response.data,
        },
      });
    },
 
    *show({ payload ,callback}, { call, put }) {
      const response = yield call(showReporting, payload); 
      yield put({
        type: 'query',
        payload: {
          inquiryList: response.data,
          // loading: false,
        },
      });
      if(callback)callback();
    },

    *updata({ payload ,callback}, { call, put }) {
      yield put({
        type: 'changeQuerise',
        payload: true,
      });
      const response = yield call(updata, payload);
      yield put({
        type: 'changeQuerise',
        payload: false,
      });
      if(response.result.code=="200"){
        message.success('修改成功');
        
      }else{
        message.error(response.result.message);
      }
      yield put({
        type: 'query',
        payload: {
          data: response,
          // loading: false,
        },
      });
      if(callback)callback();
    },

    *fetchThirdDataCreate({ payload ,callback}, { call, put }) {
      yield put({
        type: 'query',
        payload: {
          thirdDataLoading: true,
        },
      });
      const response = yield call(fetchThirdDataCreate, payload);
      yield put({
        type: 'query',
        payload: {
          thirdDataLoading: false,
        },
      });
      yield put({
        type: 'query',
        payload: {
          data: response.data,
          thirdDataResult: response.result,
        },
      });
      if(callback)callback();
    },

    *fetchThirdData({ payload ,callback}, { call, put }) {
      yield put({
        type: 'query',
        payload: {
          loading: true,
        },
      });
      const response = yield call(fetchThirdData, payload); 
      yield put({
        type: 'query',
        payload: {
          loading: false,
        },
      });
      if(response.result.code=="200"){
        yield put({
          type: 'query',
          payload: {
            thirdData: response.data.list,
            thirdDataPage: response.data.page,
            thirdDataResult: response.result
          },
        });
      }else{
        message.error(response.result.message)
      }
      if(callback)callback();
    },

    *fetchThirdDataDetails({ payload ,callback}, { call, put }) {
      yield put({
        type: 'query',
        payload: {
          sumbitLoading: true,
        },
      });
      const response = yield call(fetchThirdDataDetails, payload); 
      yield put({
        type: 'query',
        payload: {
          sumbitLoading: false,
        },
      });
      if(response.result.code=="200"){
        yield put({
          type: 'query',
          payload: {
            thirdDataDetails: response.data,
          },
        });
      }else{
        message.error(response.result.message)
      }
      if(callback)callback();
    },
  },
  

  
  reducers: {//纯函数， 输入什么输出就是什么
    query(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
    changeQuerise(state, { payload }) {
      return {
        ...state,
        sumbitLoading: payload,
      };
    },
  },
};
